<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/summernote/summernote.css}" rel="stylesheet"/>
<link th:href="@{/ajax/libs/summernote/summernote-bs3.css}" rel="stylesheet"/>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-lvyou-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">标题：</label>
				<div class="col-sm-8">
					<input id="lvTitle" name="lvTitle" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">变更日期：</label>
				<div class="col-sm-8">
					<input type="text" class="time-input" id="lvChangedate" placeholder="变更日期" name="lvChangedate"/>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">信息来源：</label>
				<div class="col-sm-8">
					<input id="lvOriginal" name="lvOriginal" class="form-control" type="text">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">一级类别：</label>
				<div class="col-sm-8">
					<select id="category1"  class="form-control m-b"  name="lvLb1"
							data-rel="chosen">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">二级类别：</label>
				<div class="col-sm-8">
					<select id="category2"  class="form-control m-b"  name="lvLb2"
							data-rel="chosen">
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">三级类别：</label>
				<div class="col-sm-8">
					<select id="category3"  class="form-control m-b"  name="lvLb3"
							data-rel="chosen">
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">所在省：</label>
				<div class="col-sm-8">
					<select id="area1"  class="form-control m-b"  name="lvProvince"
							data-rel="chosen">
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">所在市：</label>
				<div class="col-sm-8">
					<select id="area2"  class="form-control m-b"  name="lvCity"
							data-rel="chosen">
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">所在县：</label>
				<div class="col-sm-8">
					<select id="area3"  class="form-control m-b"  name="lvCountry"
							data-rel="chosen">
					</select>
				</div>
			</div>

			<div class="form-group">	
				<label class="col-sm-3 control-label">批次：</label>
				<div class="col-sm-8">
					<input id="lvPici" name="lvPici" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">审批机构：</label>
				<div class="col-sm-8">
					<input id="lvShenpijc" name="lvShenpijc" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">级别：</label>
				<div class="col-sm-8">
					<input id="lvLevels" name="lvLevels" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">详细内容：</label>
				<div class="col-sm-8">
					<input id="lvDetails" name="lvDetails"  type="hidden">
					<div id="editor" class="summernote"></div>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/summernote/summernote.min.js}"></script>
	<script th:src="@{/ajax/libs/summernote/summernote-zh-CN.js}"></script>
    <script type="text/javascript">
		var prefix = ctx + "system/lvyou"
		var prefix1 = ctx + "system/category"
		var prefix2 = ctx + "system/area"
		$(function() {
			initCategrey();
			initArea();
			$('.summernote').summernote({
				height : '220px',
				lang : 'zh-CN',
				callbacks: {
					onImageUpload: function (files) {
						sendFile(files[0], this);
					}
				}
			});
		});

		// 上传文件
		function sendFile(file, obj) {
			var data = new FormData();
			data.append("file", file);
			$.ajax({
				type: "POST",
				url: ctx + "common/upload",
				data: data,
				cache: false,
				contentType: false,
				processData: false,
				dataType: 'json',
				success: function(result) {
					if (result.code == web_status.SUCCESS) {
						// $(obj).summernote('editor.insertImage', result.url, result.fileName);
                        $(obj).summernote('editor.insertImage', img_root + result.fileName, result.fileName);
					} else {
						$.modal.alertError(result.msg);
					}
				},
				error: function(error) {
					$.modal.alertWarning("图片上传失败。");
				}
			});
		}

		$("#form-lvyou-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
				var sHTML = $('.summernote').summernote('code');
				$("#lvDetails").val(sHTML);
	            $.operate.save(prefix + "/add", $('#form-lvyou-add').serialize());
	        }
	    }

		function initCategrey() {


			cate1();
			cate2();
			$("#category1").change(function () {
				cate2();

			});
			$("#category2").change(function () {
				cate3($("#category2").val());
			});

		}
		function cate1() {
			$.get(
					prefix1 + "/list?parentId=100&deptId=102",
					function (data) {
						if (data) {
							var result = "";
							$.each(data, function (n, value) {
								result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
							});
							$("#category1").html(result);
						}
					}, "json");
		}

		function cate2() {
			$.get(
					prefix1 + "/list?parentId=102",
					function (data) {
						if (data) {
							var result = "";
							$.each(data, function (n, value) {

								if(n ==0){
									cate3(value.deptId);
								}
								result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
							});
							$("#category2").html(result);


						}
					}, "json");
		}
		function cate3(id) {
			$.get(
					prefix1 + "/list?parentId=" + id,
					function (data) {
						if (data) {
							var result = '';
							$.each(data, function (n, value) {
								result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
							});

							$("#category3").html(result);
						}
					}, "json");
		}


		function initArea() {


			farea1();
			farea21();
			farea31();
			$("#area1").change(function () {
				farea2($("#area1").val());

			});
			$("#area2").change(function () {
				farea3($("#area2").val());
			});

		}
		function farea1() {
			$.get(
					prefix2 + "/list?parentId=1",
					function (data) {
						if (data) {
							var result = "";
							$.each(data, function (n, value) {
								result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
							});
							$("#area1").html(result);
						}
					}, "json");
		}
		function farea21() {
			$.get(
					prefix2 + "/list?parentId=110000",
					function (data) {
						if (data) {
							var result = "";
							$.each(data, function (n, value) {
								result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
							});
							$("#area2").html(result);
						}
					}, "json");
		}
		function farea31() {
			$.get(
					prefix2 + "/list?parentId=110100",
					function (data) {
						if (data) {
							var result = "";
							$.each(data, function (n, value) {
								result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
							});
							$("#area3").html(result);
						}
					}, "json");
		}

		function farea2(id) {
			$.get(
					prefix2 + "/list?parentId="+ id,
					function (data) {
						if (data) {
							//$("#area2").html("<option value=''>市辖区</option>");
							var result = "";
							$.each(data, function (n, value) {
								if(n==0)
								{
									farea3(value.deptId);
								}

								//farea3($("#area2").val());

								result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
							});
							$("#area2").html(result);


						}
					}, "json");
		}
		function farea3(id) {
			$.get(
					prefix2 + "/list?parentId=" + id,
					function (data) {
						if (data) {
							//$("#area3").html("<option value=''>东城区</option>");
							var result = "";
							$.each(data, function (n, value) {
								result += "<option value='" + value.deptId + "'>" + value.deptName + "</option>";
							});

							$("#area3").html(result);
						}
					}, "json");
		}

	</script>
</body>
</html>
